<%@ page pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/base/taglibs.jsp"%>

<html>
	<head>
		<link href="${ctx}/css/main.css" rel="stylesheet" type="text/css" />
		<script language="javascript">
		function submitAction(action){
			document.adForm.action = action ;
			document.adForm.submit();
		}
		
		function init(){
			document.getElementById("adDesc").value = "";
			document.getElementById("localFile").outerHTML = document.getElementById("localFile").outerHTML;
		}	
		
		function select(action,id){
			location.href = "${ctx}/" + action + "?id=" + id;
		}
		
		function clickFile(action,fileName){
			location.href = "${ctx}/" + action + "?fileName=" + fileName;
		}
		
		function saveAction(action) { 
			if(document.getElementById('adType').value == '') {
				alert('请输入文件类型');
				return false;
			}
			if(document.getElementById('adLocation').value == '') {
				alert('请输入页面位置');
				return false;
			}
			if(document.getElementById('url').value == '') {
				alert('请输入广告链接地址');
				return false;
			}
			if(document.getElementById('id').value == '' && document.getElementById('localFile').value == '') {
				alert('请选择上传文件');
				return false;
			}
			submitAction(action);
		}
		
		function doDelete(action,id){
			if(confirm('是否确认删除？')){
				location.href = "${ctx}/" + action + "?id=" + id ;
			}
		}
	</script>	
	
	</head>
	<form method="post" action="" name="adForm" ENCTYPE="multipart/form-data">
			<table border="0" cellspacing="1" cellpadding="3" align="center" width="100%">
				<tr>
					<td class="td11" align="left" colspan="4">
						<input type="button" name="save" value="保存" onClick="saveAction('saveNewAd.ac');">
						<c:if test="${empty adManage.id}">
							&nbsp;&nbsp;<input type="button" name="reset" value="重置" onClick="init()" >
						</c:if>
						<c:if test="${!empty adManage.id}">
							&nbsp;&nbsp;<input type="button" name="reset" value="删除" onClick="doDelete('deleteAd.ac','${ad.id}');" >
						</c:if>
						&nbsp;&nbsp;<input type="button" name="reset" value="返回" onClick="submitAction('adBack.ac');">
					</td>
				</tr>
				<tr>
					<td width="10%" class="td2"> 
						文件类型 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="50%" class="td2">
						<input type="hidden" name="id" value="${adManage.id}" >
						<input type="hidden" name="adFilename" value="${adManage.adFilename}" >
						<select name="adType" style="width:200px" id="adType">
							<c:forEach var ="adType" items="${sessionScope.T_adTypeList}">
								<c:if test="${adManage.adType == adType.typeCode}">
									<option value="${adType.typeCode}" selected="selected">${adType.typeName}</option>
								</c:if>
								<c:if test="${adManage.adType != adType.typeCode}">
									<option value="${adType.typeCode}">${adType.typeName}</option>
								</c:if>
							</c:forEach>
						</select>
					</td>
				</tr>
				<tr>
					<td width="10%" class="td2">  
						页面位置 <span style="color:red;vertical-align:middle;">*</span> 
					</td>
					<td width="30%" class="td2">
						<select name="adLocation" style="width:200px" id="adLocation"> 
							<c:forEach var ="adLocation" items="${sessionScope.T_adLocationList}">
								<c:if test="${adManage.adLocation == adLocation.typeCode}">
									<option value="${adLocation.typeCode}" selected="selected">${adLocation.typeName}</option>
								</c:if>
								<c:if test="${adManage.adLocation != adLocation.typeCode}">
									<option value="${adLocation.typeCode}">${adLocation.typeName}</option>
								</c:if>
							</c:forEach>
						</select>
					</td>
				</tr>
					<td width="10%" class="td2">  
						广告链接地址 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="50%" class="td2">
						<input type="text" name="url" size="90" value="${adManage.url}" >
					</td>
				</tr>
				<tr>
					<td width="10%" class="td2">  
						选择上传文件 <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="50%" class="td2">
						<input type="file" name="localFile" size="40" value="">
					</td>
				</tr>
				<tr>
					<td width="10%" class="td2">  
						文件
					</td>
					<td width="30%" class="td2">
						<a href="javascript:clickFile('getAdContent.ac','${adManage.adFilename}');">${adManage.adFilename}</a>
					</td>
				</tr>
				<tr>
					<td width="10%" class="td2">  
						文件描述 
					</td>
					<td width="50%" class="td2">
						<textarea name="adDesc" rows="4" cols="80">${adManage.adDesc}</textarea>
					</td>
				</tr>	
			</table>
		</form>
	
</html>